#include "lib.h"
#include "WeightedOutcomes.h"

#include <algorithm>

bool operator<(const WeightedOutcome& lhs, const WeightedOutcome& rhs)
{
    return lhs.first < rhs.first;
}

uint32 getOutcome( const WeightedOutcomes& outcomes, uint32 testValue, uint32 defaultVal )
{
    WeightedOutcomes::const_iterator notFound = outcomes.end();

    WeightedOutcomes::const_iterator target = std::find_if( outcomes.begin(), 
                                                            notFound, 
                                                            Hits( testValue ) );

    if ( target != notFound )
    {
        return target->second;
    }

    return defaultVal;
}

uint32 getOutcome( WeightedOutcomes& outcomes, uint32 testValue, uint32 defaultVal )
{
    return getOutcome( static_cast<const WeightedOutcomes&>( outcomes ), testValue, defaultVal );
}

uint32 getOutcome( const WeightedOutcomes& outcomes, uint32 testValue )
{
    return getOutcome( outcomes, testValue, 0 );
}

uint32 getOutcome( WeightedOutcomes& outcomes, uint32 testValue )
{
    return getOutcome( outcomes, testValue, 0 );
}